<%-- 
    Document   : productDetails
    Created on : Jul 6, 2011, 3:10:43 PM
    Author     : ThanhToan
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<link rel="stylesheet" href="screen.css" type="text/css" media="screen, projection"/>
<%@ page import="java.util.List" %>
<%@ page import="java.util.Iterator" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<%@ page import="dao.ProductDAO" %>
<%@ page import="dao.CategoriesDAO" %>
<%@ page import="model.ProductModel" %>
<%@ page import="model.CategoriesModel" %>
<%@page import="java.util.ArrayList"%>

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Product Details Page</title>

        <script type="text/javascript" language="JavaScript">
            function submitFormProDetails(){
                document.forms["productDetails"].submit();
            }

            function urlImage(){
                document.getElementById("txtImage").value = document.forms["productDetails"].fileImage.value;
            }
        </script>

        <c:choose>
            <c:when test="${not empty param.proID}">
                <c:set var="objProDetails" value = '<%= ProductDAO.getProductByProID(request.getParameter("proID"))%>' scope="session"></c:set>
            </c:when>
            <c:otherwise>
                <c:set var="objProDetails" value = "${requestScope.productInfo}" scope="session"></c:set>
            </c:otherwise>
        </c:choose>

    </head>
    <body>
        <div id="main_container">
		<!-- S HEAD CONTENT -->
			<jsp:include page="block/header.jsp" />
		<!-- E HEAD CONTENT -->

		<!-- S Top Menu -->
			<jsp:include page="block/top_menu.jsp" />
		<!-- E Top Menu -->

                <!-- S Left Menu -->
			<jsp:include page="block/left_menu.jsp" />
		<!-- E Left Menu -->

		<!-- S Body Content -->
                <div class="center_content">
                <%--<form action="<%=request.getContextPath()%>/ProductController?proDetail=yes" method="post" id="productDetails" name="productDetails">
                    <input type= "hidden" id="ID" name = "ID" value = "${param.proID}" />
                    <c:if test="${not empty param.err}">
                            <b class="error"> Input into the mandatory fields (*) </b>
                    </c:if>
                    <c:if test="${not empty param.msg and param.msg eq 'CreateNew'}">
                            <b class="msg"> Create new product success </b>
                    </c:if>
                    <c:if test="${(not empty param.msg and param.msg eq 'update')}">
                            <b class="msg"> Update product details success </b>
                    </c:if>

                    <input type="hidden" id="actionType" name="actionType"
			<c:choose>
                            <c:when test="${empty param.proID}">
                                value="CreateNew"
                            </c:when>
                            <c:otherwise>
                                value="Update"
                            </c:otherwise>
			</c:choose>
                    />

                    <table border="0" cellpadding="3" cellspacing="8" align="center">
                        <tr>
                            <td align="center" colspan="4"> <h1>Product Details</h1> </td>
                        </tr>
                        <tr>
                            <td>Product name : </td>
                            <td>
                                <input type="text" id="txtProName" name="txtProName" maxlength="100" style="background: transparent; color: blue; width: 200px" value="${objProDetails.proName}"/>
                            </td>

                        </tr>
                        <tr>
                            <td>Catogories : </td>
                            <td>
                                <select name="cboCategories" id="cboCategories" onchange="" style="width: 200px">
                                    <option value=""> ------------------ </option>
                                    <c:forEach var="objCategories" items="<%= CategoriesDAO.getAllCategories() %>">
                                        <option value="${objCategories.id}"  <c:if test="${objCategories.id eq objProDetails.cateID}"> selected </c:if> >${objCategories.cateName}</option>
                                    </c:forEach>
                                </select>
                            </td>
                        </tr>
                        <c:if test="${not empty objProDetails.image}">
                            <tr>
                                <td>Image : </td>
                                <td>
                                    <img name="image" id="image" src="${objProDetails.image}" alt="" border="0" />
                                </td>
                            </tr>
                        </c:if>
                        <tr>
                            <td>Image New: </td>
                            <td><input name="fileImage" type="file" id="fileImage" onchange="urlImage()" src="abc" /></td>
                        </tr>
                        <tr>
                            <td>Description : </td>
                            <td>
                                <textarea id="txtProDes" name="txtProDes" rows="5" cols="25" style="background-color: transparent; background-position: left">${objProDetails.proDes}</textarea>
                            </td>
                        </tr>
                        <tr>
                            <td>Price : </td>
                            <td>
                                <input type="text" id="txtPrice" name="txtPrice" maxlength="80" style="background: transparent; color: blue; width: 200px" value="${objProDetails.price}"/> (USD)
                            </td>
                        </tr>
                        <tr>
                            <td align="center" colspan="2">
                                <c:if test="${empty objProDetails}">
                                    <input type="button" id="btSub" name="btSub" value="Submit" style="width: 70px; color: navy" onclick="submitFormProDetails();"/>
                                </c:if>
                                <c:if test="${not empty objProDetails}">
                                    <input type="button" id="btSub" name="btSub" value="Update" style="width: 70px; color: navy" onclick="submitFormProDetails();"/>
                                </c:if>
                                <input type="reset" id="btReset" name="btReset" value="Reset" style="width: 70px; color: navy"/>
                            </td>
                        </tr>
                    </table>
                </form>--%>

                <div id="productMain" class="span-14 last">
                        <h2 class="alt">${objProDetails.proName}</h2>
                            <div id="productImage" class="span-7">
                                <c:choose>
                                    <c:when test="${ not empty objProDetails.image }">
                                        <c:forTokens items="${objProDetails.image}" delims="|" var="image" end="0">
                                            <a href="" title="${objProDetails.proName}" class="thickbox" rel="gallery-product">
                                                <img alt="${objProDetails.proName}" src="${objProDetails.image}" width="270px" border="0" />
                                            </a>
                                        </c:forTokens>
                                    </c:when>
                                    <c:otherwise>
                                        <img alt="${objProDetails.proName}" src="images/noimg.jpg" width="125px" border="0" />
                                    </c:otherwise>
                                </c:choose>
                            </div>
                                <div id="priceStack" class="span-7 last">
                                    <div id="topPriceStack">
                                        <div id="bottomPriceStack">
                                            <form id="frmAddToCart" action="" method="post">
                                                <table cellpadding="2" cellspacing="0">
                                                    <tr>
                                                        <td><label>Price:</label></td>
                                                        <td><span class="productPrice"><fmt:formatNumber maxFractionDigits="2" value="${ objProDetails.price }" type="currency" /></span></td>
                                                    </tr>
                                                    <tr>
                                                        <td><label>Available:</label></td>
                                                        <td>Available</td>
                                                    </tr>
                                                    <tr>
                                                        <td><label>Category:</label></td>
                                                        <td>
                                                            <a href="showproduct.jsp?cateID=${objProDetails.cateID}">
                                                                ${ objProDetails.cateName }
                                                            </a>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td><label>Description</label></td>
                                                        <td>
                                                            ${ objProDetails.proDes}
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td></td>
                                                        <td>
                                                            <input type="hidden" name="txtProductId" value="${ objProDetails.id }" />
                                                            <input type="button" value="Add to cart" name="btnAddCart" class="cart-button"
                                                                <c:if test="${not empty sessionScope.userID}" >
                                                                   onclick='location.href="ShoppingCardController?action=add&productID=${objProDetails.id}"' </c:if>/>
                                                        </td>
                                                    </tr>
                                                </table>
                                            </form>
                                        </div>
                                    </div>
                                </div>
                    </div>
		<!-- E Body Content -->
                </div>
	</div>
    </body>
</html>
